package createThread.cn.tedu.threaddemo.test7;

public class Demo2 {
    public static int count = 0;

    public static final String locker = "锁1";

    public static void add(){
        synchronized (locker){
            count++;
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            synchronized (locker){
                for (int i = 1; i <= 100; i++) {
                    count++;
                }
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 1; i <= 100 ; i++) {
                synchronized (locker){
                    Demo2.add();
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count: " + count);
    }
}
